let app = getApp();
let util = require("../../utils/utils.js");
console.log(util)
Page({
    data: {
        loginSuccess: false,
        step: null,
        getStep: false,
        bigpicList: [{src:app.resPath + "img/banner.jpg"}],
        popupImg: app.resPath + "img/popup.jpg",
        popupShow: false
    },
    onLoad: function(e) {
        //console.log(wx.getStorageSync('userInfo') )
        let user = app.getUserInfo();
        // todo
        if(!user) {
            wx.reLaunch({
              url: '/pages/login/login',
            })
        }
        else {
            this.setData({
                loginSuccess: true
            })
            this.getMyStepData();
        }
        //console.log(user)
        // var s = this;
        // wx.showLoading(), console.log("首页options: ", e);
        // var o = "";
        // if (e.userid && (o = e.userid), e.scene) {
        //     console.log("首页options.scene: ", e.scene);
        //     var a = decodeURIComponent(e.scene);
        //     console.log("首页解码后的scene: ", a), t.default.getUrlParams("uid", a) && (o = t.default.getUrlParams("uid", a));
        // }
        // i.login(function() {
        //     wx.hideLoading();
        //     var e = {
        //         who: i.who
        //     };
        //     i.shopMsg.shop && i.shopMsg.shop.copy_right && (e.copy_right = i.shopMsg.shop.copy_right), 
        //     s.setData(e), s.getMyStepData(), s.isUserinfo(), s.indexpageSet(), s.adinfo();
        // }, o);
    },
    onShow: function() {
        wx.hideHomeButton();
        this.showPopup();
    },
    showPopup() {
        if(app.indexShow){
            return;
        }
        this.setData({
            popupShow: true
        })
        app.indexShow = true;
    },
    closePopup(){
        this.setData({
            popupShow: false
        })
    },
    getMyStepData: function() {
        this.setData({
            getStep: true
        });
        util.getWechatStep(1, (t)=> {
            if (-1 === t) {
                this.setData({
                    getStep: !1
                })
                util.showToast("步数获取失败,请下拉重新获取", "none", 2000)
                return;
            } 
            this.setData({
                getStep: false,
                step: t
            });
        });
    },

    exchange: function() {
        wx.navigateTo({
            url: "/pages/luxian/luxian"
        });
    },
    onPullDownRefresh: function() {
        this.setData({
            step: null
        });
        this.getMyStepData();
        wx.stopPullDownRefresh();
    },
});